package com.winit.openapi.wop.inbound.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;

import com.winit.openapi.controller.BaseController;
import com.winit.openapi.model.RequestMsg;
import com.winit.openapi.model.ResponseMsg;
import com.winit.ums.spi.EorIorInfoService;
import com.winit.ups.spi.customstrade.IorEorTypeService;
import com.winit.ups.spi.customstrade.command.QueryIorEorTypeForListCommand;
import com.winit.ups.spi.customstrade.vo.IorEorTypeVo;
import com.winit.ups.spi.warehouse.WarehouseService;

/**
 * Eor类型设置对外api
 * 
 * @version
 * 
 * <pre>
 * Author	Version		Date		Changes
 * qiyongkang 	1.0  		2017年7月25日 	Created
 * </pre>
 * 
 * @since 1.
 */
@Controller
@RequestMapping(value = "winit/ups/eorType")
public class WHInboundEorTypeController extends BaseController {

    private static Logger     logger = LoggerFactory.getLogger(WHInboundEorTypeController.class);
    @Resource
    private IorEorTypeService iorEorTypeService;
    @Resource
    private EorIorInfoService eorIorInfoService;

    @Resource
    private WarehouseService  upsWarehouseService;

    @RequestMapping(value = "/queryEorList")
    public String queryEorDataByCondition(@ModelAttribute RequestMsg requestMsg,
                                          @ModelAttribute ResponseMsg responseMsg) {
        List<Map<String, Object>> resultList = this.queryEorData();
        responseMsg.setData(resultList);
        return SUCCESS;
    }

    /**
     * 查询出EOR类型并组装.
     * 
     * @param countryCode
     * @return
     */
    private List<Map<String, Object>> queryEorData() {
        List<Map<String, Object>> resultList = new ArrayList<Map<String, Object>>();

        // 先查询出所有的EOR类型
        QueryIorEorTypeForListCommand command = new QueryIorEorTypeForListCommand();
        command.setType("EOR");
        List<IorEorTypeVo> list = iorEorTypeService.queryByParamForList(command);

        if (list == null || list.size() == 0) {
            logger.info("未查询到EOR类型");
            return resultList;
        }

        // 遍历
        for (IorEorTypeVo iorEorTypeVo : list) {
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("code", iorEorTypeVo.getCode());
            map.put("name", iorEorTypeVo.getName());
            resultList.add(map);
        }
        return resultList;
    }
}
